package org.nicocube.airain.domain.server.data;

import org.nicocube.airain.domain.client.data.OrderedStorable;
import org.nicocube.airain.domain.client.data.Storable;
import org.nicocube.airain.domain.client.data.StorageException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * This component is a provider with factory methods for {@link Storage} and {@link OrderedStorage} 
 * 
 * @author nicolas
 * @version 0.1
 */
public class StorageProvider {
	private static final Logger log = LoggerFactory.getLogger(StorageProvider.class);

	private final ContainerProvider containerProvider;

	public StorageProvider(ContainerProvider containerProvider) {
		this.containerProvider = containerProvider;
	}
	
	/**
	 * Factory method for building <tt>OrderedStorage&lt;T&gt;</tt>
	 * 
	 * @param <T>
	 * @param clazz
	 * @return
	 * @throws StorageException
	 */
	public <T extends OrderedStorable> OrderedStorage<T> getStorage(Class<T> clazz) throws StorageException {
		log.info("creation of a new OrderedStorage for "+clazz.getName());
		return new OrderedStorage<T>(clazz,containerProvider);
	}
	
	/**
	 * Factory method for building <tt>Storage&lt;T&gt;</tt>
	 * 
	 * @param <T>
	 * @param clazz
	 * @return
	 * @throws StorageException
	 */
	public <T extends Storable> Storage<T> getStorage(Class<T> clazz) throws StorageException {
		log.info("creation of a new Storage for "+clazz.getName());
		return new Storage<T>(clazz,containerProvider);
	}
}
